<template>
  <ConfigProvider :locale="getAntdLocale">
    <router-view v-slot="{ Component }">
      <component :is="Component" />
    </router-view>
  </ConfigProvider>
</template>

<script setup lang="ts">
import { watchEffect, onMounted, onUnmounted, watch } from 'vue';
import { ConfigProvider } from 'ant-design-vue';
import { useRoute, useRouter } from 'vue-router';
import { useLocale } from '@/locales/useLocale';
import { transformI18n } from '@/framework/hooks/useI18n';
const route = useRoute();
const router = useRouter();
const { getAntdLocale } = useLocale();

watchEffect(() => {
  if (route.meta?.title) {
    // 翻译网页标题
    document.title = transformI18n(route.meta.title);
  }
});

watch(
  () => route.name,
  () => {
    if (route.name == undefined) return;
    window.$wujie?.bus.$emit('sub-router-change', 'sample', route.path);
  },
);

onMounted(() => {
  window.$wujie?.bus.$on('sample-router-change', (path) => {
    console.error(path, 'path box');
    router.push(path);
  });
});
onUnmounted(() => {
  window.$wujie?.bus.$off('sample-router-change');
});
</script>

<style lang="less"></style>
